# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_luaversions="5.1 5.2 5.3 5.4"
pkgname=lua-discount
pkgver=1.2.10.1
pkgrel=8
pkgdesc="Markdown implementation in C for Lua"
url="https://asbradbury.org/projects/lua-discount"
arch="all"
license="custom" # BSD-based custom license
subpackages="$pkgname-doc"
for _i in $_luaversions; do
	makedepends="$makedepends lua$_i-dev"
	subpackages="$subpackages lua$_i-discount:split_${_i/./_}"
done
source="https://dev.alpinelinux.org/archive/lua-discount/lua-discount-$pkgver.tar.gz"
options="!check"

build() {
	cd "$srcdir"
	for i in $_luaversions; do
		cp -r $pkgname-$pkgver $i
		(cd $i; make INCS="$(pkg-config --cflags lua$i)")
	done
}

package() {
	cd "$srcdir"
	for i in $_luaversions; do
		install -D -m644 $i/discount.so \
			"$pkgdir"/usr/lib/lua/$i/discount.so
	done
	install -Dm644 "$builddir"/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

_split() {
	local _ver=$1
	pkgdesc="$pkgdesc $_ver"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	depends=""
	mkdir -p "$subpkgdir"/usr/lib/lua/
	mv "$pkgdir"/usr/lib/lua/$_ver "$subpkgdir"/usr/lib/lua/
}

for _v in $_luaversions; do
	eval "split_${_v/./_}() { _split $_v; }"
done

sha512sums="
84c26a19d97ca085c785d1916b05bc0c78a2b5a0965d7feeef9a545c4b69c71627791c5d560bcb529c9ed414ed2ebe99f253879d6eae593a5b6f93291d66d5b1  lua-discount-1.2.10.1.tar.gz
"
